package com.elem.web;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.elem.bean.Food;
import com.elem.bean.User;
import com.elem.service.FoodService;
import com.elem.service.UserService;
import com.elem.service.impl.FoodServiceImpl;
import com.elem.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

// 目前只有两个：一个是登录，一个是注册
@WebServlet("/FoodController/*")
public class FoodServlet extends BaseServlet {

    FoodService foodService = new FoodServiceImpl();
    ObjectMapper objectMapper = new ObjectMapper();



    public void listFoodByBusinessId(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

       // 接收商家的id
        String businessId = req.getParameter("businessId");
        try {
            List<Food> foodList = foodService.listFoodByBusinessId(Integer.parseInt(businessId));
            objectMapper.writeValue(resp.getOutputStream(), foodList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}